package cn.javabb.project.service;

import cn.javabb.common.web.BaseEntity;
import cn.javabb.project.entity.GenTableColumn;
import cn.javabb.project.mapper.GenTableColumnMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: javabb (javabob(a)163.com)
 * @create: 2021/03/26 18:12
 */
@Slf4j
@Service
public class GenTableColumnService extends ServiceImpl<GenTableColumnMapper, GenTableColumn> {

    public List<GenTableColumn> listByTableId(String tableId) {
        List<GenTableColumn> list = this.list(new QueryWrapper<GenTableColumn>().eq("table_id", tableId));
        return list;
    }

    public List<GenTableColumn> listByIds(List<String> idList) {
        LambdaQueryWrapper<GenTableColumn> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.in(GenTableColumn::getTableId, idList);
        queryWrapper.orderByAsc(GenTableColumn::getSort);
        List<GenTableColumn> columns = this.list(queryWrapper);
        return columns;
    }

    public boolean deleteByTableId(String tableId) {
        QueryWrapper<GenTableColumn> query = new QueryWrapper();
        query.eq("table_id", tableId);
        return this.remove(query);
    }

    public boolean deleteByTableIds(List<String> tableIds) {
        QueryWrapper<GenTableColumn> query = new QueryWrapper();
        query.in("table_id", tableIds);
        return this.remove(query);
    }
}
